package com.sample.service;

import org.springframework.jms.core.JmsTemplate;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;

/**
 * Created by IntelliJ IDEA.
 * User: khanhpham
 * Date: 10/25/11
 * Time: 8:27 AM
 * To change this template use File | Settings | File Templates.
 */
public class JmsReceiver {
   private JmsTemplate jmsTemplate;
   private Destination topic;

   public JmsReceiver(JmsTemplate template, Destination topic) {
      this.jmsTemplate = template;
      this.topic = topic;
   }

   public Message receive() throws JMSException {
      Message message = jmsTemplate.receive(topic);
      ObjectMessage om = (ObjectMessage)message;
      String text = (String) om.getObject();
      return message;
   }
}
